package com.innovation.chengzhangriji.ui;

import android.content.Intent;
import android.os.Bundle;

import com.google.gson.Gson;
import com.innovation.chengzhangriji.Config;
import com.innovation.chengzhangriji.database.DatabaseManager;
import com.innovation.chengzhangriji.http.Auth;
import com.innovation.chengzhangriji.http.BabyResponse;
import com.innovation.chengzhangriji.preferences.LoginInfo;

public abstract class BaseLoginActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    protected final void setLoginInfo(LoginInfo loginInfo) {
        Gson gson = new Gson();
        String loginValue = gson.toJson(loginInfo);
        Config.setLoginInfo(this, loginValue);
    }

    protected final void insertOrReplaceInTxBabyAndParent(String id, Auth[] auth, int... babyIDArray) {
        DatabaseManager.getInstance(this).insertOrReplaceInTxBabyAndParent(id, auth, babyIDArray);
    }

    protected final void insertOrReplaceInTxBaby(BabyResponse... babyResponses) {
        DatabaseManager.getInstance(this).insertOrReplaceInTxBaby(babyResponses);
    }

    protected final void startTimelineActivity() {
        Intent intent = new Intent(this, HomeActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        startActivity(intent);
        finish();
    }

}
